package com.lizi.domian;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.annotation.JSONField;
import com.lizi.core.util.JsonUtil;

public class UserBean extends BaseBean{

	private String name;
	
	@JSONField(name="_name")
	private String _name;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@JSONField(name="_name")
	public String get_name() {
		return _name;
	}
	
	public void set_name(String _name) {
		this._name = _name;
	}
	
	@Override
	public boolean equals(Object obj) {
		return JsonUtil.toJson(obj).equals(JsonUtil.toJson(this));
    }
	
	@Override
	public String toString() {
		return JsonUtil.toJson(this);
    }
	
	public static void main(String[] args) {
		UserBean user1 = new UserBean();
		UserBean user2 = new UserBean();
		
		System.out.println(user1.equals(user2));//true
		
		user1.set_name("name");
		System.out.println(user1.equals(user2));//false
		
		user2.set_name("name");
		System.out.println(user1.equals(user2));//true
		
		user2 = null;
		System.out.println(user1.equals(user2));//false
		
		System.out.println("==============");
		List<UserBean> list1 =new ArrayList<>();
		user1 = new UserBean();
		user1.name = "1";
		user1._name = "2";
		list1.add(user1);
		user1 = new UserBean();
		user1.name = "111";
		list1.add(user1);
		user1 = new UserBean();
		user1.name = "2222";
		list1.add(user1);
		
		List<UserBean> list2 =new ArrayList<>();
		user2 = new UserBean();
		user2.name = "1";
		user2._name = "2";
		list2.add(user2);
		user2 = new UserBean();
		user2.name = "312312";
		list2.add(user2);
		user2 = new UserBean();
		user2.name = "1";
		user2._name = "2asdasd";
		list2.add(user2);
		
		Map<String,Integer> map= new HashMap<>();
		for(int i =0;i< list1.size();i++){
			map.put(list1.get(i).toString(),i );
		}
		
		List<UserBean> list = new ArrayList<>();
		int[] array = new int[list1.size()];
		for(int i =0;i< list2.size();i++){
			Integer index = map.get(list2.get(i).toString());
			if(index == null){
				list.add(list2.get(i));
			} else {
				array[index] = 1;
			}
		}
		
		for(int i=0;i<list1.size();i++){
			if(array[i] != 1){
				list.add(list1.get(i));
			}
		}
		
		for(UserBean user: list){
			System.out.println(user);
		}
		
	}
	
	
}
